<?php

namespace App\Models\Customer;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * Class BannerType
 *
 * @method static self filterHasHairTry(int $has_hair)
 *
 * @mixin Builder
 */
class BannerType extends Model
{
    /**
     * 前端选择的 bannerable 类型，按店铺还是按设备显示
     */
    const BANNER_TYPE_STORE = 'Store';
    const BANNER_TYPE_DEVICE_ACCOUNT = 'DeviceAccount';

    const ID_TO_PRODUCT = 2; // 跳转商品
    const ID_TO_HAIR_TRYON = 5; // 跳转发型试戴

    protected $table = 'banner_types';

    protected $guarded = [];

    /**
     * 根据客户有无发型试戴，返回对应的banner_type
     * @used-by filterHasHairTry
     *
     * @param Builder $query
     * @param $has_hair
     * @return $this|Builder
     */
    public function scopeFilterHasHairTry(Builder $query, $has_hair)
    {
        if ($has_hair) return $query;

        return $query->where('id', '<>', self::ID_TO_HAIR_TRYON);
    }
}
